home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 223_01 / fb.c < prev    next >
Text File  |  1980-01-01  |  1KB  |  47 lines

  1. /*    
  2. ** fb.c        File Copy (Bin) Program        by F.A.Scacchitti  7/17/84
  3. **
  4. **        Written in Small-C Version 2.7 or later
  5. **
  6. **        Copies file from file to file
  7. **        Byte modifications may be made during transfer
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. #define BUFSIZE 0x4000  /* 16K */
  13.  
  14. FILE fdin, fdout;    /* file  i/o channel pointers */
  15. int i, count;
  16. char *inbuf;
  17.  
  18. main(argc,argv) int argc; char *argv[]; {
  19.  
  20.    i = 0;
  21.    inbuf = malloc(BUFSIZE);
  22.  
  23.    if(argc != 3) {
  24.     puts("\nfb usage: fb <source file> <new file> <CR>\n");
  25.     exit();
  26.    }
  27.    if((fdin = fopen(argv[1],"r")) == NULL) {
  28.       puts("\nUnable to open input file.\n");
  29.       exit();
  30.    }
  31.    if((fdout = fopen(argv[2],"w")) == NULL) {
  32.       puts("\nUnable to create output file.\n");
  33.       exit();
  34.    }
  35.  
  36.    while((count = read(fdin,inbuf,BUFSIZE)) == BUFSIZE) {
  37.       write(fdout,inbuf,count);
  38.       i += count;
  39.    }
  40.    i += count;
  41.    write(fdout,inbuf,count);
  42.  
  43.    fclose(fdin);
  44.    fclose(fdout);
  45. }
  46.  
  47.